document.addEventListener( "plusready",  function()
{
var _WEBRTC = "webrtc",
    B = window.plus.bridge;

    var webrtc =
    {
        init : function (key,mode)
            {
                return B.execSync(_WEBRTC, "init", [key,mode]);
            },
        connectRoom : function (key,roomId,successCallback,errorCallback)
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
               {
                   successCallback(args);
               },
               fail = typeof errorCallback !== 'function' ? null : function(code)
               {
                   errorCallback(code);
               };
               callbackID = B.callbackId(success, fail);
                return B.exec(_WEBRTC, "connectRoom", [callbackID,key,roomId,successCallback,errorCallback]);
            },
        sendMessage : function (key,msg,successCallback,errorCallback)
            {
            var success = typeof successCallback !== 'function' ? null : function(args)
               {
                   successCallback(args);
               },
               fail = typeof errorCallback !== 'function' ? null : function(code)
               {
                   errorCallback(code);
               };
               callbackID = B.callbackId(success, fail);
                return B.exec(_WEBRTC, "sendMessage", [callbackID,key,msg,successCallback,errorCallback]);
            },
        disconnectRoom : function (key,successCallback,errorCallback)
                    {
                    var success = typeof successCallback !== 'function' ? null : function(args)
                       {
                           successCallback(args);
                       },
                       fail = typeof errorCallback !== 'function' ? null : function(code)
                       {
                           errorCallback(code);
                       };
                       callbackID = B.callbackId(success, fail);
                        return B.exec(_WEBRTC, "disconnectRoom", [callbackID,key,successCallback,errorCallback]);
                    },
         sendFile : function (key,filepath,successCallback,errorCallback)
                     {
                     var success = typeof successCallback !== 'function' ? null : function(args)
                        {
                            successCallback(args);
                        },
                        fail = typeof errorCallback !== 'function' ? null : function(code)
                        {
                            errorCallback(code);
                        };
                        callbackID = B.callbackId(success, fail);
                         return B.exec(_WEBRTC, "sendFile", [callbackID,key,filepath,successCallback,errorCallback]);
                     }
    };
    window.plus.webrtc = webrtc;
}, true );


var Webrtc = function(){
}

Webrtc.prototype.init = function(key,mode){
    plus.webrtc.init(key,mode);
}

Webrtc.prototype.connectRoom = function(key,roomId,successCallback,errorCallback){
    plus.webrtc.connectRoom(key,roomId,successCallback,errorCallback);
}

Webrtc.prototype.disconnectRoom = function(key,successCallback,errorCallback){
    plus.webrtc.disconnectRoom(key,successCallback,errorCallback);
}

Webrtc.prototype.sendMessage = function(key,msg,successCallback,errorCallback){
    plus.webrtc.sendMessage(key,msg,successCallback,errorCallback);
}

Webrtc.prototype.sendFile = function(key,filepath,successCallback,errorCallback){
    plus.webrtc.sendFile(key,filepath,successCallback,errorCallback);
}
